package com.masterrabbit.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.masterrabbit.common.log.annotation.Log;
import com.masterrabbit.common.log.enums.BusinessType;
import com.masterrabbit.common.security.annotation.RequiresPermissions;
import com.masterrabbit.domain.Reviews;
import com.masterrabbit.service.IReviewsService;
import com.masterrabbit.common.core.web.controller.BaseController;
import com.masterrabbit.common.core.web.domain.AjaxResult;
import com.masterrabbit.common.core.utils.poi.ExcelUtil;
import com.masterrabbit.common.core.web.page.TableDataInfo;

/**
 * 评价信息Controller
 * 
 * @author laotu
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/reviews")
public class ReviewsController extends BaseController
{
    @Autowired
    private IReviewsService reviewsService;

    /**
     * 查询评价信息列表
     */
    @RequiresPermissions("masterrabbit-kaixuan:reviews:list")
    @GetMapping("/list")
    public TableDataInfo list(Reviews reviews)
    {
        startPage();
        List<Reviews> list = reviewsService.selectReviewsList(reviews);
        return getDataTable(list);
    }

    /**
     * 导出评价信息列表
     */
    @RequiresPermissions("masterrabbit-kaixuan:reviews:export")
    @Log(title = "评价信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Reviews reviews)
    {
        List<Reviews> list = reviewsService.selectReviewsList(reviews);
        ExcelUtil<Reviews> util = new ExcelUtil<Reviews>(Reviews.class);
        util.exportExcel(response, list, "评价信息数据");
    }

    /**
     * 获取评价信息详细信息
     */
    @RequiresPermissions("masterrabbit-kaixuan:reviews:query")
    @GetMapping(value = "/{reviewId}")
    public AjaxResult getInfo(@PathVariable("reviewId") Long reviewId)
    {
        return success(reviewsService.selectReviewsByReviewId(reviewId));
    }

    /**
     * 新增评价信息
     */
    @RequiresPermissions("masterrabbit-kaixuan:reviews:add")
    @Log(title = "评价信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Reviews reviews)
    {
        return toAjax(reviewsService.insertReviews(reviews));
    }

    /**
     * 修改评价信息
     */
    @RequiresPermissions("masterrabbit-kaixuan:reviews:edit")
    @Log(title = "评价信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Reviews reviews)
    {
        return toAjax(reviewsService.updateReviews(reviews));
    }

    /**
     * 删除评价信息
     */
    @RequiresPermissions("masterrabbit-kaixuan:reviews:remove")
    @Log(title = "评价信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reviewIds}")
    public AjaxResult remove(@PathVariable Long[] reviewIds)
    {
        return toAjax(reviewsService.deleteReviewsByReviewIds(reviewIds));
    }
}
